<extend name='Index/index' />

<block name="main">
                <div class="bg-light lter b-b wrapper-md">
                    <h1 class="m-n font-thin h3">英雄图片管理</h1>
                </div>
                <div class="wrapper-md">
                    <div class="panel panel-default">
                        <div class="table-responsive">
                            <table class="table table-striped b-t b-light">
                                <thead>
                                    <tr>
                                        <th>英雄ID</th>
                                        <th>英雄名称</th>
                                        <th>英雄头像</th>
                                        <th>技能1图像</th>
                                        <th>技能2图像</th>
                                        <th>技能3图像</th>
                                        <th>技能4图像</th>
                                        <th>操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <volist name='data' id='c'>
                                    <tr>
                                        <td><{$c.c_id}></td>
                                        <td><{$c.h_name}></td>
                                        <td> <img width="100" height="100" src="__PUBLIC__/Uploads/icon/<{$c.icon}>" alt=""></td>
                                        <td><img width="100" src="__PUBLIC__/Uploads/icon/<{$c.s1_icon}>" alt=""></td>
                                        <td><img width="100" src="__PUBLIC__/Uploads/icon/<{$c.s2_icon}>" alt=""></td>
                                        <td><img width="100" src="__PUBLIC__/Uploads/icon/<{$c.s3_icon}>" alt=""></td>
                                        <td><img width="100" src="__PUBLIC__/Uploads/icon/<{$c.s4_icon}>" alt=""></td>
                                        <td>
                                        <a   class='btn btn-info' data-toggle="modal" data-target="#myModal" > 添加图像</a> 
                                        </td>
                                    </tr>
                                    </volist>
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
<!-- 编辑英雄的模态框 -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" id="guanbi" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
                    </button>
                    <h4 class="modal-title" id="myModalLabel">修改图像</h4>
                </div>
                    <form class="form-horizontal" role="form" action="<{:U('Admin/Icon/edit')}>" method="post" enctype= 'multipart/form-data'>
                <div class="modal-body">
                    
                        <div class="form-group">
                            <label for="inputEmail" class="col-sm-2 control-label">英雄ID</label>
                            <div class="col-sm-9">
                                <input type="email" class="form-control" name="c_id" id="id" readonly="" value="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputEmail" class="col-sm-2 control-label">英雄名称</label>
                            <div class="col-sm-9">
                                <input type="text" class="form-control" name="h_name" id="h_name" readonly="" value="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputphone" class="col-sm-2 control-label">英雄头像</label>
                            <div class="col-sm-9">
                                <input type="file" name="icon" id="icon" value="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputphone" class="col-sm-2 control-label">技能1图标</label>
                            <div class="col-sm-9">
                                <input type="file" name="s1" id="s1" value="">
                                
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputphone" class="col-sm-2 control-label">技能2图标</label>
                            <div class="col-sm-9">
                                <input type="file" name="s2" id="s2" value="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputphone" class="col-sm-2 control-label">技能3图标</label>
                            <div class="col-sm-9">
                                <input type="file"  name="s3" id="s3" value="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputphone" class="col-sm-2 control-label">技能4图标</label>
                            <div class="col-sm-9">
                                <input type="file"  name="s4" id="s4" value="">
                            </div>
                        </div>
                </div>
                <div class="modal-footer">
                    <button id="close" type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button id="save" type="submit" class="btn btn-primary">confirm</button>
                </div>
            </form>
            </div>
        </div>
    </div>


<script type="text/javascript">
    $(function(){
        $("a:contains('添加图像')").click(function(){
            var id = $(this).parents('tr').children('td').eq(0).html();
            var name = $(this).parents('tr').children('td').eq(1).html();
            var icon = $(this).parents('tr').children('td').eq(2).val();
            $('#id').val(id);
            $('#h_name').val(name);
        })
            $("a:contains('删除')").click(function(){
                var id = $(this).parents('tr').children('td').eq(0).html();
                $(this).parents('tr').remove();
                $.ajax({
                url:"<{:U('d')}>",
                type:"POST",
                data:{'c_id':id},
                dataType:'json', 
                success: function(data){
                        if(data == 1){
                            alert('删除成功');
                        }else{
                            alert('删除失败');
                        }
                    }
                })
            })

            $('#add').click(function(){
                var id = '';
                var name = $('#addname').val();
                if(name==""){
                    alert('英雄名不能为空');
                    return false;
                }
                var src = $('#addsrc').val();
                if(src == ""){
                    alert('小头像地址不能为空');
                    return false;
                }
                var b_src = $('#addb_src').val();
                if(b_src == ""){
                    alert('英雄大头像地址不能为空');
                    return false;
                }
                var detail = $('#adddetail').val();
                if(detail == ""){
                    alert('英雄描述不能为空');
                    return false;
                }
                var type = $('#addtype').val();
                if(type == ""){
                    alert('英雄类型不能为空');
                    return false;
                }
                $.ajax({
                url:"<{:U('add')}>",
                type:"POST",
                data:{'h_id':id,'h_name':name,'h_name':src,'h_icon':src,'h_iconHover':b_src,'h_detail':detail,'h_type':type},
                dataType:'json', 
                success: function(data){
                    // console.log(data);
                    if(data > 0){
                        alert('添加成功');
                         window.location.reload();
                    }else{
                        alert('添加失败');
                        return false;
                    }
                    }
                })
            })
    })
</script>
</block>
